|
Technote 1129LaserWriter 8.5.1: The Settings Libraryand Richard Blanchard, RBI Software Systems, Inc. |
CONTENTS
The Settings Library and |
The Settings Library ( |
PrintingLib
SettingsLib
is a code fragment which lives within the PrintingLib
file. SettingsLib
is used by the other code fragments in PrintingLib
, as well as by LaserWriter 8, in order to access stored printer information. You should link against PrintingLib
in order to gain access to the SettingsLib
APIs.psGetPrintingPrefsFolder
psGetPrintingPrefsFolder()
. This API can also be used if you wish to determine where to place printing-related data.OSStatus psGetPrintingPrefsFolder(short *vRef, long *folderId);
*vRef
and the directory ID is placed into *folderId
. If the folder does not exist and cannot be created, then an error is returned.psGetPrefsPrinterInfo
PAPA
handle that identifies a printer, the psGetPrefsPrinterInfo()
routine can be used to get a collection containing the printer’s information. The client can then use the Collection Manager to access the individual items within the collection. It is the client’s responsibility to dispose of the collection using the Collection Manager’s DisposeCollection()
. For more information on the Collections Manager, please see Inside Macintosh: QuickDraw GX Environment and Utilities.Collection psGetPrefsPrinterInfo(StringPtr prefsName, Handle papa);
PAPA
. The information is taken from the printing preferences file, whose name is prefsName
. If the collection cannot be obtained, then NULL is returned.PAPA
is used to target an individual printer in the database. The PAPA
consists of three Pascal strings packed together, followed by data that is unique to the communications method for the given printer. In other words, the data after the three Pascal strings is not inspected by the SettingsLib
, and its contents are up to the client.1 The three Pascal strings at the start of the PAPA
are the printer’s name, the network object type, and the printer’s zone. These three strings identify a given printer database entry; together, they form a unique key to the database. Please see Technote 1115: "The Extended PAPA
Resource" for more information.psUpdatePrefsPrinterInfo
and psRemovePrefsPrinterInfo
psUpdatePrefsPrinterInfo()
to replace the existing collection for a given printer. Even after calling psUpdatePrefsPrinterInfo()
, it is the client’s responsibility to dispose of the collection. To remove a printer from the database completely, use psRemovePrefsPrinterInfo()
.OSErr psUpdatePrefsPrinterInfo(StringPtr prefsName, Handle papa, Collection prInfo);
prInfo
(for the printer specified by PAPA
) into the preferences database named prefsName. All information associated with the printer specified by PAPA
is replaced with the information contained in prInfo
.OSErr psRemovePrefsPrinterInfo(StringPtr prefsName, Handle papa, Collection prInfo);
PAPA
from the
printing preferences file named prefsName
. If PAPA
is NULL, then prInfo
is searched for a printer name hint, which is then used to choose the entry to be deleted from the preferences database.APPL
along with an ID that is your registered creator type. For example, Adobe Acrobat should store its data as tag APPL
and ID CARO
. Thus, each application gets only a single slot in the database. We further recommend that the data stored in that single slot be a flattened collection in which you can use any tags and IDs you want.#define kHintAppPrivateTagAPPL
#define kHintAppPrivateId // Application's creator type.
#define kHintAppPrivateVar // A flattened collection.
Note: |
psCountPrefsPrinters
and psGetPrefsIndName
psCountPrefsPrinters()
to get the total number of printers in a database. Once the total number of printers is known, the client can enumerate over the printers by handing an index from 1 to the total number of printers (inclusive) with psGetPrefsIndName()
. psGetPrefsIndName()
then returns the printer name and zone name of the indexed printer info collection.2 long psCountPrefsPrinters(StringPtr prefsName);
OSErr psGetPrefsIndName(StringPtr prefsName, long index, StringPtr name, StringPtr zone);
psGetPrefsIndName()
to enumerate over the printer info collections in the printer database specified by prefsName
. index should be between 1 and psCountPrefsPrinters()
, inclusive. For each index, this function fills in name
with the printers name and zone
with the printers zone. On entry, name
and zone
must point to at least Str32
arrays of characters. The client can use the returned name
and zone
to build a PAPA that can be handed to the other settings routines.PAPA
and SettingsLib
PrintingLib
8.5.1 supports the use of an extended PAPA
record as described in Technote 1115: "The Extended PAPA
Resource." In order to limit the number of clients who need to deal directly with the extended PAPA
format, the Settings Library provides routines for creating extended PAPA
handles, and for setting and retrieving tagged values in the PAPA
. This section describes the APIs for this use.psSetPapPapa
, psSetInfraredPapa
, psSetFilePapa
, psSetHoldPapa
, psSetLprPapa
, and psSetCustomPapa
PAPA
record, SettingsLib
clients allocate a new record via NewHandle()
and then pass the handle, a PAP printer name, object type, zone, and optional AppleTalk address block to the various psSetXXXPapa()
routines. The memory block is filled in as an extended PAPA
record for the printer.OSStatus psSetPapPapa(Handle papaH, const Byte * printer, const Byte * atType, const Byte * zone, AddrBlock *addr);
printer
), an AppleTalk device type (pointed to by atType
), and an AppleTalk zone (pointed to by zone
), this builds a PAPA in the block whose handle is papaH
. papaH
must be the handle of a memory block of at least 103 bytes long. addr
is a pointer to an AppleTalk address block. If addr
is not NULL on entry, the address block is copied after the printer-type-zone strings in the PAPA.addr
is NULL, then zeros are entered for the address in the PAPA.OSStatus psSetInfraredPapa(Handle papaH, const Byte * printer, const Byte * zone);
papaH
, with an extended PAPA
describing an infrared printer. Together, printer
and zone
should uniquely identify a printer since this pair is used as a key to store information in the printer database. papaH
must be the handle of a memory block of at least 103 bytes long.OSStatus psSetFilePapa(Handle papaH, const Byte * printer, const Byte * zone);
papaH
with an extended PAPA
describing a save to file desktop printer.
Together, printer
and zone
should uniquely identify a printer since this pair is used as a key to store information in the printer database. papaH
must be the handle of a memory block of at least 103 bytes long.OSStatus psSetHoldPapa(Handle papaH, const Byte * printer, const Byte * zone);
papaH
with an extended PAPA
describing a hold desktop printer. Together, printer
and zone
should uniquely identify a printer since this pair is used as a key to store information in the printer database. papaH
must be the handle of a memory block of at least 103 bytes long.OSStatus psSetLprPapa(Handle papaH, const Byte * printer, const Byte * zone, const Byte * tcpAddr, const Byte * qName);
papaH
with an extended PAPA
describing an lpr
desktop printer. Together, printer
and zone
should uniquely identify a printer since this pair is used as a key to store information in the printer database. tcpAddr
is the network address of the lpr
printer.qName
is the name of the print queue associated with a spooler at tcpAddr
. If qName
is NULL, then the default queue for the printer/spooler is used. papaH
must be the handle of a memory block of at least 1024 bytes long.OSStatus psSetCustomPapa(Handle papaH, const Byte * printer, const Byte * zone);
papaH
, with an extended PAPA
describing a custom desktop printer. Together, printer
and zone
; should uniquely identify a printer since this pair is used as a key to store information in the printer database. See Technote 1113: "Customizing Desktop Printer Utility" for more information.psPapaToCollection
and psCollectionToPapa
PAPA
record, the routines psPapaToCollection()
and psCollectionToPapa()
can be used to access and set extended PAPA
tag block. The routine psPapaToCollection()
takes a handle to an extended PAPA
record and a collection, and copies the tag values from the extended PAPA
into the collection. The client can then use the Collection Manager to enumerate and alter the tag values. The call psCollectionToPapa()
takes the tags from a collection and copies them into an extended PAPA
record, replacing any tags that may already be there.OSStatus psPapaToCollection(Handle papaH, Collection coll);
papaH
, and a collection, coll
,
psPapaToCollection()
creates a set of collection items in coll
, all of which have the tag PAPA
and whose ID is the tag from the extended PAPA
record. For example, if the extended PAPA record papaH
has a tag with type TCP
, then the data for that tag will be placed into coll
with tag PAPA
and ID TCP
. The TAGS
value from the extended PAPA is not copied into the collection.OSStatus psCollectionToPapa(Collection coll, Handle papaH);
coll
, this routine enumerates the collection items with the tag PAPA
and makes them part of the extended PAPA record whose handle is papaH
. The ID of the collection item becomes the tag in the PAPA. Any existing tags in the PAPA record papaH
are replaced. The error errNoRoomInPapa (-8941)
is returned if all of the tags do not fit. All of the tags that do fit are added into the PAPA
.psGetDTPType
PAPA
and needs to know the type of printer described by that PAPA
, psGetDTPType()
can be used.psGetDTPType()
function will classify a desktop printer described by a PAPA
handle as being one of the following DTPType's:typedef enum{ kInvalidDTP = 0, // An invalid DTP type. kHoldDTP = '=Hld', // Hold DTP's spool job to a print queue which // is always on hold. kFileDTP = '=Fil', // Save to file DTP's can't print; they just // create PS/PDF files. kLprDTP = '=LPR', // LPR printers print over TCP to LPR // spoolers/printers. kCustomDTP = '=Cst', // Custom DTP's launch an app to post-process // the PostScript. kPapaDTP = 'PAP ', // An AppleTalk PAP network printer. kInfraRedDTP = '=Ird' // A printer connected via an infrared link. } DTPType;
OSStatus psGetDTPType(Handle papaH, DTPType *dtpTypeP);
PAPA
handle, papaH
, this routine will place the DTP type into *dtpTypeP
. If there is an error, then an error value is returned and *dtpTypeP
is set to kInvalidDTP
.psIsValidPapaHandle
psIsValidPapaHandle()
tries to determine if a PAPA
handle is valid. It will return false if the PAPA
seems to be invalid.Boolean psIsValidPapaHandle(Handle papaH);
papaH
looks to be a valid PAPA handle.PAPA
Resource"1 There are printer driver limitations on the PAPA
that do not affect the SettingsLib
. In particular, due to the "MultiFinder Friendly" bit, printer drivers are not allowed to change the size of the PAPA
resource stored in the driver. Thus, the driver's PAPA
is a fixed size.
2 Notably lacking from the return values for psGetPrefsIndName()
is the network object name. Today, all of the printer database entries have a network object name of "LaserWriter." A new routine will be added in the future to deal with this limitation.